﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("YUIAspNet");

YUIAspNet.Slider = function(element) {
    YUIAspNet.Slider.initializeBase(this, [element]);
}

YUIAspNet.Slider.prototype = {
    initialize: function() {
        YUIAspNet.Slider.callBaseMethod(this, 'initialize');
       	 
	    //Sys.Application.add_init(Function.createDelegate(this, this.initializeSlider));
    },

    initializeYUIControl: function() {
       var Event = YAHOO.util.Event, 
	        Dom   = YAHOO.util.Dom, 
	        lang  = YAHOO.lang, 
	        slider;
        
        if(this.get_SliderOrientation() == 0)
            slider = YAHOO.widget.Slider.getVertSlider(
                    this.get_SliderBg(), this.get_SliderThumb(), 
                    this.get_MinValue(), this.get_MaxValue(), this.get_IncrementSize()); 
        else if (this.get_SliderOrientation() == 1)
            slider = YAHOO.widget.Slider.getHorizSlider(
                    this.get_SliderBg(), this.get_SliderThumb(), 
                    this.get_MinValue(), this.get_MaxValue(), this.get_IncrementSize()); 
        
        
        var handler = null; 
        if(this._events)
            handler = this._events.getHandler("onChange");

        var wrappedSlider = this;
        var incrementFactor = this.get_IncrementFactor();
        
        slider.subscribe("change", function() {
                       
            if(handler)
            {
                var args = {value: slider.getValue()*incrementFactor};
                handler(wrappedSlider, args); 
            }
        });
 
        // set an initial value 
        slider.setValue(this.get_InitialValue()*this.get_IncrementFactor()); 
        
        this._yuiControl = slider;
    },
     
    dispose: function() {
        $clearHandlers(this.get_element());
            
        //Add custom dispose actions here
        YUIAspNet.Slider.callBaseMethod(this, 'dispose');
    },
    
    get_SliderBg: function() {
        return this._sliderBg;
    },
    set_SliderBg: function(sliderBg) {
        this._sliderBg = sliderBg;
    },
    
    get_SliderThumb: function() {
        return this._sliderThumb;
    },
    set_SliderThumb: function(sliderThumb) {
        this._sliderThumb = sliderThumb;
    },
    
    get_MinValue: function() {
        return this._minValue;
    },
    set_MinValue: function(minValue) {
        this._minValue = minValue;
    },
    
    get_MaxValue: function() {
        return this._maxValue;
    },
    set_MaxValue: function(maxValue) {
        this._maxValue = maxValue;
    },
    
    get_InitialValue: function() {
        return this._initialValue;
    },
    set_InitialValue: function(initialValue) {
        this._initialValue = initialValue;
    },
        
    get_SliderOrientation: function() {
        return this._sliderOrientation;
    },
    set_SliderOrientation: function(sliderOrientation) {
        this._sliderOrientation = sliderOrientation;
    },
    
    get_IncrementSize: function() {
        return this._incrementSize;
    },
    set_IncrementSize: function(incrementSize) {
        this._incrementSize = incrementSize;
    },
    
    get_IncrementFactor: function() {
        return this._incrementFactor;
    },
    set_IncrementFactor: function(incrementFactor) {
        this._incrementFactor = incrementFactor;
    },
           
    add_onChange : function(handler) {
        this.get_events().addHandler("onChange", handler);
    },

    remove_onChange : function(handler) {
        this.get_events().removeHandler("onChange", handler);
    }
}
YUIAspNet.Slider.registerClass('YUIAspNet.Slider', YUIAspNet.BaseControl);
